package com.xian.daoimpl;

import java.sql.SQLException;
import java.util.List;

import javax.jms.Session;



import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.xian.dao.SellDao;
import com.xian.domain.Greens;

import com.xian.domain.Sell;


public class SellDaoImpl extends HibernateDaoSupport implements SellDao{


	@SuppressWarnings("unchecked")
	@Override
	public List<Sell> findSellPage(final int pages) {
		
		return getHibernateTemplate().executeFind(new HibernateCallback() {
			
			@Override
			public Object doInHibernate(org.hibernate.Session session)
					throws HibernateException, SQLException {
				Query query = session.createQuery("from Sell ");
				query.setFirstResult((pages-1)*Greens.PANGESIZE);
				 query.setMaxResults(Greens.PANGESIZE);
				return query.list();
			}
		});
	}

	@Override
	public int findSellcount() {
		int n = 0;
		Query query = this.getSession().createQuery("select count(*) from Sell");
		 n = new Integer(((Long) query.uniqueResult()).toString());
		return n;
		}

	@Override
	public List<Sell> findSellSort(String hql) {
		
		return getHibernateTemplate().find(hql);
	}


	@Override
	public void deleteSell(Sell sell) {
		// TODO Auto-generated method stub
		this.getHibernateTemplate().delete(sell);
	}

	@Override
	public void addupSell(Sell sell) {
		// TODO Auto-generated method stub
		this.getHibernateTemplate().save(sell);
	}


	
}
